package com.activity;

import com.activity.R;
import com.fragment.LocateDetailsFragment;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ViewFlipper;

public class PopupImages extends Activity implements OnTouchListener{
	private ViewFlipper flipper;
	private float x1=-1,x2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.popup_image);
		flipper=(ViewFlipper) findViewById(R.id.my_view_flipper);
		flipper.setOnTouchListener(this);
		for(Bitmap bitmap:LocateDetailsFragment.locate.getImages()){
			ImageView imageView1=new ImageView(getApplicationContext());
			imageView1.setImageBitmap(bitmap);
			imageView1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
			flipper.addView(imageView1, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		}
	}
	@Override
	public boolean onTouch(View arg0, MotionEvent event) {
		// TODO Auto-generated method stub
		if(event.getAction()==MotionEvent.ACTION_DOWN)
			x1=event.getX();
		else if(event.getAction()==MotionEvent.ACTION_UP)
		{
			x2=event.getX();
			if(x2-x1>0)
			{
				flipper.showPrevious();
			}else if(x1-x2>0)
			{
				flipper.showNext();
			}
		}
		return true;
	}
}
